home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODUtil / Include / FWPoint.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  13.5 KB  |  443 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPoint.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWPOINT_H
  11. #define FWPOINT_H
  12.  
  13. #ifndef FWFXMATH_H
  14. #include "FWFxMath.h"
  15. #endif
  16.  
  17. // ----- Foundation Includes -----
  18.  
  19. #ifndef FWSTDDEF_H
  20. #include "FWStdDef.h"
  21. #endif
  22.  
  23. // ----- OpenDoc Includes -----
  24.  
  25. #ifndef _ODTYPES_
  26. #include <ODTypes.h>
  27. #endif
  28.  
  29. #ifndef SOM_ODTransform_xh
  30. #include <Trnsform.xh>
  31. #endif
  32.  
  33. #if FW_LIB_EXPORT_PRAGMAS
  34. #pragma lib_export on
  35. #endif
  36.  
  37. //========================================================================================
  38. //    Forward Declarations
  39. //========================================================================================
  40.  
  41. class FW_CLASS_ATTR ODTransform;
  42.  
  43. class FW_CLASS_ATTR FW_CRect;
  44. class FW_CLASS_ATTR FW_CPoint;
  45. class FW_CLASS_ATTR FW_CWritableStream;
  46. class FW_CLASS_ATTR FW_CReadableStream;
  47.  
  48. //========================================================================================
  49. //    Global operators << and >>
  50. //========================================================================================
  51.  
  52. FW_FUNC_ATTR const FW_CWritableStream& operator<<(const FW_CWritableStream& stream, const FW_CPoint& point);
  53. FW_FUNC_ATTR const FW_CReadableStream& operator>>(const FW_CReadableStream& stream, FW_CPoint& point);
  54.  
  55. //========================================================================================
  56. //    Global
  57. //========================================================================================
  58.  
  59. extern const FW_CPoint        FW_kZeroPoint;
  60.  
  61. //========================================================================================
  62. //    Typedefs
  63. //========================================================================================
  64.  
  65. typedef unsigned short FW_XYSelector;
  66.  
  67. const FW_XYSelector FW_kHorizontal = 0;
  68. const FW_XYSelector FW_kVertical = 1;
  69.  
  70. //========================================================================================
  71. //    struct FW_SPlatformPoint
  72. //========================================================================================
  73.  
  74. struct FW_CLASS_ATTR FW_SPlatformPoint : public FW_PlatformPoint
  75. {
  76.     FW_SPlatformPoint();
  77.     FW_SPlatformPoint(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy);
  78.     FW_SPlatformPoint(const FW_SPlatformPoint& plfmPoint);
  79.     FW_SPlatformPoint(const FW_PlatformPoint& plfmPoint);
  80.     FW_SPlatformPoint(const FW_CPoint& point);
  81.         
  82.     FW_SPlatformPoint& operator=(const FW_SPlatformPoint& plfmPoint);
  83.     FW_SPlatformPoint& operator=(const FW_PlatformPoint& plfmPoint);
  84.     FW_SPlatformPoint& operator=(const FW_CPoint& point);
  85.  
  86.     void Set(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy);
  87.     
  88.     FW_Boolean        operator==(const FW_SPlatformPoint& pt) const;
  89.     FW_Boolean        operator!=(const FW_SPlatformPoint& pt) const;
  90.  
  91.     FW_PlatformCoordinate X() const;
  92.     FW_PlatformCoordinate Y() const;
  93.  
  94.     FW_PlatformCoordinate& X();
  95.     FW_PlatformCoordinate& Y();
  96. };
  97.  
  98. //========================================================================================
  99. // class FW_CPoint
  100. //     Has the same layout as ODPoint, but the members are FW_CFixed instead of ODFixed,
  101. //    which make the class much easier to use
  102. //========================================================================================
  103.  
  104. class FW_CLASS_ATTR FW_CPoint
  105. {
  106. //----------------------------------------------------------------------------------------
  107. //    Data members
  108. //
  109. public:
  110.     FW_CFixed x, y;
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //    Constructors/Destructors
  114. //
  115. public:
  116.     FW_CPoint() : x(FW_IntToFixed(0)), y(FW_IntToFixed(0))
  117.         { }
  118.         
  119.     FW_CPoint(FW_CFixed xx, FW_CFixed yy) : x(xx), y(yy)
  120.         { }
  121.                     
  122.     FW_CPoint(FW_PlatformPoint plfmPoint);
  123.     FW_CPoint(const FW_CPoint& point);
  124.     FW_CPoint(const ODPoint& odPoint);
  125.  
  126.     FW_CPoint(const FW_CReadableStream& stream);
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    operators
  130. //
  131. public:
  132.     // ----- Assignement -----    
  133.     FW_CPoint&         operator=(const FW_CPoint& point);
  134.     FW_CPoint&         operator=(const ODPoint& odPoint);
  135.     FW_CPoint&         operator=(FW_PlatformPoint plfmPoint);
  136.  
  137.     // ----- Conversion -----
  138. //     It is too dangerous to have automatic conversion. Use AsPlatformPoint.
  139. //    operator FW_PlatformPoint() const;
  140.     operator        ODPoint() const
  141.         { return * (ODPoint*) this; }
  142.  
  143.     // ----- Modification -----    
  144.     FW_CPoint&        operator+=(const FW_CPoint& point);
  145.     FW_CPoint&        operator-=(const FW_CPoint& point);
  146.     FW_CPoint&        operator+=(const ODPoint& odPoint);
  147.     FW_CPoint&        operator-=(const ODPoint& odPoint);
  148.     
  149.     FW_CPoint        operator+(const FW_CPoint& point) const;
  150.     FW_CPoint        operator-(const FW_CPoint& point) const;
  151.     FW_CPoint        operator+(const ODPoint& odPoint) const;
  152.     FW_CPoint        operator-(const ODPoint& odPoint) const;
  153.     FW_CPoint        operator-()  const;
  154.     
  155.     FW_CPoint&        operator+=(FW_SPlatformPoint plfmPoint);
  156.     FW_CPoint&        operator-=(FW_SPlatformPoint plfmPoint);
  157.     FW_CPoint        operator+(FW_SPlatformPoint plfmPoint) const;
  158.     FW_CPoint        operator-(FW_SPlatformPoint plfmPoint) const;
  159.  
  160.     FW_CFixed&         operator[](FW_XYSelector selector);
  161.     FW_CFixed         operator[](FW_XYSelector selector) const;
  162.     
  163.     // ----- Comparison    -----
  164.     FW_Boolean        operator==(const FW_CPoint& point)    const;
  165.     FW_Boolean        operator!=(const FW_CPoint& point)    const;
  166.     FW_Boolean        operator==(const ODPoint& odPoint)     const;
  167.     FW_Boolean        operator!=(const ODPoint& odPoint)     const;
  168.         
  169. //----------------------------------------------------------------------------------------
  170. //    New API
  171. //
  172. public:
  173.     // ----- Modification -----    
  174.     void             Clear();
  175.     void             Set(FW_CFixed xx, FW_CFixed yy);
  176.     void            Offset(FW_CFixed xx, FW_CFixed yy);
  177.     void            Map(const FW_CRect& srcRect, const FW_CRect& destRect);
  178.  
  179.     // ----- Conversion -----
  180.     void            AsPlatformPoint(FW_PlatformPoint& plfmPoint) const;
  181.  
  182.     // ----- Accessors -----
  183.     short            IntX() const;
  184.     short            IntY() const;
  185.     
  186.     // ----- OpenDoc transforms -----
  187.     void            Transform(Environment* ev, ODTransform* trasnsform);
  188.     void            InverseTransform(Environment* ev, ODTransform* transform);
  189.         // Modify the point
  190.  
  191.     FW_CPoint        TransformCopy(Environment* ev, ODTransform* trasnsform) const;
  192.     FW_CPoint        InverseTransformCopy(Environment* ev, ODTransform* transform) const;
  193.         // Return a transformed copy
  194.  
  195.     // ----- Utilities -----
  196.     static FW_XYSelector GetOrthogonal(FW_XYSelector selector)
  197.                                 {return (selector + 1) & 1;}    
  198. };
  199.  
  200. //========================================================================================
  201. //    inlines
  202. //========================================================================================
  203.  
  204. //----------------------------------------------------------------------------------------
  205. //    FW_CPoint::Clear
  206. //----------------------------------------------------------------------------------------
  207.  
  208. inline void FW_CPoint::Clear()
  209. {
  210.     x = y = FW_IntToFixed(0);
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    FW_CPoint::Set
  215. //----------------------------------------------------------------------------------------
  216. inline void FW_CPoint::Set(FW_CFixed xx, FW_CFixed yy)
  217. {
  218.     x = xx, y = yy;
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_CPoint::IntX
  223. //----------------------------------------------------------------------------------------
  224. inline short FW_CPoint::IntX() const
  225. {
  226.     return x.AsInt();
  227. }
  228.  
  229. //----------------------------------------------------------------------------------------
  230. //    FW_CPoint::IntY
  231. //----------------------------------------------------------------------------------------
  232. inline short FW_CPoint::IntY() const
  233. {
  234.     return y.AsInt();
  235. }
  236.  
  237. //----------------------------------------------------------------------------------------
  238. //    FW_SPlatformPoint::FW_SPlatformPoint
  239. //----------------------------------------------------------------------------------------
  240. inline FW_SPlatformPoint::FW_SPlatformPoint()
  241. {
  242. #ifdef FW_BUILD_WIN
  243.     x = y = 0;
  244. #endif
  245. #ifdef FW_BUILD_MAC
  246.     h = v = 0;
  247. #endif
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    FW_SPlatformPoint::FW_SPlatformPoint
  252. //----------------------------------------------------------------------------------------
  253. inline FW_SPlatformPoint::FW_SPlatformPoint(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
  254. {
  255. #ifdef FW_BUILD_WIN
  256.     x = xx; y = yy;
  257. #endif
  258. #ifdef FW_BUILD_MAC
  259.     h = xx; v = yy; 
  260. #endif
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. //    FW_SPlatformPoint::FW_SPlatformPoint
  265. //----------------------------------------------------------------------------------------
  266. inline FW_SPlatformPoint::FW_SPlatformPoint(const FW_CPoint& point)
  267. {
  268. #ifdef FW_BUILD_WIN
  269.     x = point.x.AsInt(), y = point.y.AsInt();
  270. #endif
  271. #ifdef FW_BUILD_MAC
  272.     h = point.x.AsInt(), v = point.y.AsInt();
  273. #endif
  274. }
  275.  
  276. //----------------------------------------------------------------------------------------
  277. //    FW_SPlatformPoint::FW_SPlatformPoint
  278. //----------------------------------------------------------------------------------------
  279. inline FW_SPlatformPoint::FW_SPlatformPoint(const FW_SPlatformPoint& plfmPoint)
  280. {
  281. #ifdef FW_BUILD_WIN
  282.     x = plfmPoint.x; y = plfmPoint.y;
  283. #endif
  284. #ifdef FW_BUILD_MAC
  285.     h = plfmPoint.h; v = plfmPoint.v;
  286. #endif
  287. }
  288.  
  289. //----------------------------------------------------------------------------------------
  290. //    FW_SPlatformPoint::FW_SPlatformPoint
  291. //----------------------------------------------------------------------------------------
  292. inline FW_SPlatformPoint::FW_SPlatformPoint(const FW_PlatformPoint& plfmPoint)
  293. {
  294. #ifdef FW_BUILD_WIN
  295.     x = plfmPoint.x; y = plfmPoint.y;
  296. #endif
  297. #ifdef FW_BUILD_MAC
  298.     h = plfmPoint.h; v = plfmPoint.v;
  299. #endif
  300. }
  301.  
  302. //----------------------------------------------------------------------------------------
  303. //    FW_SPlatformPoint::operator=
  304. //----------------------------------------------------------------------------------------
  305. inline FW_SPlatformPoint& FW_SPlatformPoint::operator=(const FW_CPoint& point)
  306. {
  307. #ifdef FW_BUILD_WIN
  308.     x = point.x.AsInt(), y = point.y.AsInt();
  309. #endif
  310. #ifdef FW_BUILD_MAC
  311.     h = point.x.AsInt(), v = point.y.AsInt();
  312. #endif
  313.     return *this;
  314. }
  315.  
  316. //----------------------------------------------------------------------------------------
  317. //    FW_SPlatformPoint::operator=
  318. //----------------------------------------------------------------------------------------
  319. inline FW_SPlatformPoint& FW_SPlatformPoint::operator=(const FW_SPlatformPoint& plfmPoint)
  320. {
  321. #ifdef FW_BUILD_WIN
  322.     x = plfmPoint.x; y = plfmPoint.y;
  323. #endif
  324. #ifdef FW_BUILD_MAC
  325.     h = plfmPoint.h; v = plfmPoint.v; 
  326. #endif
  327.     return *this;
  328. }
  329.  
  330. //----------------------------------------------------------------------------------------
  331. //    FW_SPlatformPoint::operator=
  332. //----------------------------------------------------------------------------------------
  333. inline FW_SPlatformPoint& FW_SPlatformPoint::operator=(const FW_PlatformPoint& plfmPoint)
  334. {
  335. #ifdef FW_BUILD_WIN
  336.     x = plfmPoint.x; y = plfmPoint.y;
  337. #endif
  338. #ifdef FW_BUILD_MAC
  339.     h = plfmPoint.h; v = plfmPoint.v; 
  340. #endif
  341.     return *this;
  342. }
  343.  
  344. //----------------------------------------------------------------------------------------
  345. //    FW_SPlatformPoint::Set
  346. //----------------------------------------------------------------------------------------
  347. inline void FW_SPlatformPoint::Set(FW_PlatformCoordinate xx, FW_PlatformCoordinate yy)
  348. {
  349. #ifdef FW_BUILD_WIN
  350.     x = xx; y = yy;
  351. #endif
  352. #ifdef FW_BUILD_MAC
  353.     h = xx; v = yy;
  354. #endif
  355. }
  356.  
  357. //----------------------------------------------------------------------------------------
  358. //    FW_SPlatformPoint::X
  359. //----------------------------------------------------------------------------------------
  360. inline FW_PlatformCoordinate FW_SPlatformPoint::X() const
  361. {
  362. #ifdef FW_BUILD_WIN
  363.     return x;
  364. #endif
  365. #ifdef FW_BUILD_MAC
  366.     return h;
  367. #endif
  368. }
  369.  
  370. //----------------------------------------------------------------------------------------
  371. //    FW_SPlatformPoint::Y
  372. //----------------------------------------------------------------------------------------
  373. inline FW_PlatformCoordinate FW_SPlatformPoint::Y() const
  374. {
  375. #ifdef FW_BUILD_WIN
  376.     return y;
  377. #endif
  378. #ifdef FW_BUILD_MAC
  379.     return v;
  380. #endif
  381. }
  382.  
  383. //----------------------------------------------------------------------------------------
  384. //    FW_SPlatformPoint::X
  385. //----------------------------------------------------------------------------------------
  386. inline FW_PlatformCoordinate& FW_SPlatformPoint::X()
  387. {
  388. #ifdef FW_BUILD_WIN
  389.     return x;
  390. #endif
  391. #ifdef FW_BUILD_MAC
  392.     return h;
  393. #endif
  394. }
  395.  
  396. //----------------------------------------------------------------------------------------
  397. //    FW_SPlatformPoint::Y
  398. //----------------------------------------------------------------------------------------
  399.  
  400. inline FW_PlatformCoordinate& FW_SPlatformPoint::Y()
  401. {
  402. #ifdef FW_BUILD_WIN
  403.     return y;
  404. #endif
  405. #ifdef FW_BUILD_MAC
  406.     return v;
  407. #endif
  408. }
  409.  
  410. //----------------------------------------------------------------------------------------
  411. //    FW_SPlatformPoint::operator==
  412. //----------------------------------------------------------------------------------------
  413.  
  414. inline FW_Boolean FW_SPlatformPoint::operator==(const FW_SPlatformPoint& pt) const
  415. {
  416. #ifdef FW_BUILD_WIN
  417.     return x == pt.x && y == pt.y;
  418. #endif
  419. #ifdef FW_BUILD_MAC
  420.     return h == pt.h && v == pt.v;
  421. #endif
  422. }
  423.  
  424. //----------------------------------------------------------------------------------------
  425. //    FW_SPlatformPoint::operator!=
  426. //----------------------------------------------------------------------------------------
  427.  
  428. inline FW_Boolean FW_SPlatformPoint::operator!=(const FW_SPlatformPoint& pt) const
  429. {
  430. #ifdef FW_BUILD_WIN
  431.     return x != pt.x || y != pt.y;
  432. #endif
  433. #ifdef FW_BUILD_MAC
  434.     return h != pt.h || v != pt.v;
  435. #endif
  436. }
  437.  
  438. #if FW_LIB_EXPORT_PRAGMAS
  439. #pragma lib_export off
  440. #endif
  441.  
  442. #endif
  443.